﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuTouTiaoAssist.Util
{
    class Log
    {
        private static FileStream stream;

        static Log()
        {
            var logPath = Application.StartupPath + "\\Log\\";
            var logFile = logPath + "log_" + DateTime.Now.ToString("yyyyMMdd") + ".log";
            if (!Directory.Exists(logPath))
                Directory.CreateDirectory(logPath);
            if(!File.Exists(logFile))
                File.Create(logFile).Close();

            stream = new FileStream(logFile, FileMode.Append, FileAccess.Write);
        }

        public static void Write(string conent)
        {
            try
            {
                var bytes = System.Text.Encoding.UTF8.GetBytes(
                    string.Format("{0}\t{1}\r\n",
                        DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                        conent));
                stream.Write(bytes,0,bytes.Length);
                stream.Flush();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
